<?php
declare (strict_types = 1);

namespace app\controller;

use app\BaseController;
use app\model\Title;
use app\service\TitleService;
use think\App;
use think\Request;

class TitleController extends BaseController
{
    private $serice;
    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->serice = new TitleService();
    }

    public function getTitle(){
//        $data = $this->request->param(['type','subject']);
        $type = $this->request->param('type');
        $result = $this->serice->getInformation($type);
        return $this->returnJson($result);
    }

    public function addTitleOne(){
        $data = $this->request->param(['type','title','A','B','C','D','answer']);
        $result = $this->serice->createTitle($data['type'],$data['title'],$data['A'],$data['B'],$data['C'],$data['D'],$data['answer']);
        return $this->returnJson($result);
    }


    public function setTitle(Title $id) {
        $data = $this->request->param(['type','title','A','B','C','D','answer']);
        $result = $this->serice->editTitle($id->id,$data['type'],$data['title'],$data['A'],$data['B'],$data['C'],$data['D'],$data['answer']);
        return $this->returnJson($result);
    }
    public function deleteTitle(Title $id) {
        $result = $this->serice->delTitle($id->id);
        return $this->returnJson($result);
    }
}
